import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: AliceMana
 * Date: 2022-07-29
 * Time: 21:34
 */
public class Test {
    public static void main(String[] args) {
        // 在同一个类中,分别定义求两个整数和的方法 和 三个小数之和的方法。 并执行代码，求出结果
        int a = 10;
        int b = 20;
        double c = 1.5;
        double d = 2.5;
        double e = 3.5;
        System.out.println(add(a, b));
        System.out.println(add(c, d, e));
    }
    public static int add(int a, int b) {
        return a + b;
    }
    public static double add(double a, double b, double c) {
        return a + b + c;
    }

    public static void main5(String[] args) {
        // 求斐波那契数列的第n项。(迭代实现)
        Scanner in = new Scanner(System.in);
        System.out.println("请输入需要查找的第n项");
        while (in.hasNextInt()) {
            int n = in.nextInt();
            System.out.println("第"+n+"项为:"+fibonacci(n));
        }
    }
    public static long fibonacci(int n) {
        long a = 0;
        long b = 1;
        long c = 1;
        if ((n == 1) || (n == 2)) {
            return c;
        }
        while (n-2 != 0) {
            a = b;
            b = c;
            c = a+b;
            n--;
        }
        return c;
    }

    public static void main4(String[] args) {
        // 求1！+2！+3！+4！+........+n!的和
        Scanner in = new Scanner(System.in);
        System.out.println("请输入n");
        int n = in.nextInt();
        System.out.println(n+"的阶乘和:"+sumOfFactorial(n));
    }
    public static int sumOfFactorial(int n) {
        int sum = 0;
        while (n >= 1) {
            int ret = 1;
            for (int i = 1; i <= n; i++) {
                ret *= i;
            }
            sum += ret;
            n--;
        }
        return sum;
    }

    public static void main3(String[] args) {
        // 求 N 的阶乘 。
        Scanner in = new Scanner(System.in);
        System.out.println("请输入n：");
        int n = in.nextInt();
        System.out.println(n+"!="+getFactorial(n));
    }
    public static int getFactorial(int n) {
        int ret = 1;
        for (int i = 1; i <= n; i++) {
            ret *= i;
        }
        return ret;
    }

    public static void main2(String[] args) {
        // 创建方法求两个数的最大值max2，随后再写一个求3个数的最大值的函数max3。
        // 要求：在max3这个函数中，调用max2函数，来实现3个数的最大值计算
        int a = 10;
        int b = 20;
        int c = 30;
        System.out.println(max2(a, b));
        System.out.println(max3(a, b, c));
    }
    public static int max2(int a, int b) {
        return a>b?a:b;
    }
    public static int max3(int a, int b, int c) {
        if (max2(a, b) > c) {
            return max2(a, b);
        } else {
            return c;
        }
    }


    public static void main1(String[] args) {
        // 在同一个类中定义多个方法：要求不仅可以求2个整数的最大值，还可以求3个小数的最大值？
        int a = 10;
        int b = 20;
        double c = 1.5;
        double d = 2.0;
        double e = 2.5;
        System.out.println(getMax(a, b));
        System.out.println(getMax(c, d, e));
    }
    public static int getMax(int a, int b) {
        return a>b?a:b;
    }
    public static double getMax(double a, double b, double c) {
        double tmp = 0;
        if (a > b) {
            tmp = a;
        } else {
            tmp = b;
        }
        if (tmp > c) {
            return tmp;
        } else {
            return c;
        }
    }
}
